<template>
  <div>
    <Loadmore
      :bottom-all-loaded="allLoaded"
      :bottom-method="getData"
      :top-method="refresh"
      ref="loadmore">
      <Cell
        @click.native="handleJump(item)"
        v-for="(item, index) in list"
        :key="index"
        :title="item.title"
        :status="item.status"
        :time="item.create_time"/>
      <div slot="bottom" class="bottom">
        {{allLoaded?"数据已全部加载": "上拉加载"}}
      </div>
    </Loadmore>
  </div>
</template>

<script>
  // import {} from 'mint-ui'
  import Cell from './components/cell';
  import {Loadmore} from 'mint-ui';


  export default {
    name: "repairRecordAll",
    components: {
      Cell,
      Loadmore
    },
    data() {
      return {
        activeItem: '',
        page: 0,
        list: [],
        allLoaded: false
      }
    },
    methods: {
      getData() {
        this.page++;
        this.$axios.get("/admin/repairRecord", {
          page: this.page,
          repair_man: this.$store.state.userInfo.id
        }).then(res => {
          this.list = [...this.list, ...res.data];
          this.$refs.loadmore.onTopLoaded();
          this.$refs.loadmore.onBottomLoaded();
          if(res.data&&res.data.length > 0){
            this.allLoaded = true;
          }
        }).catch(err => console.log(err))
      },
      refresh() {
        this.page = 0;
        this.list = [];
        this.allLoaded = false;
        this.getData();
      },
      handleJump(item) {
        this.$router.push({
          name: 'details',
          query: {
            id: item._id
          }
        })
      }
    },
    created() {
      this.getData();
    }
  }
</script>

<style scoped lang="scss">
  .bottom {
    font-size: 12px;
    line-height: 40px;
    height: 40px;
    text-align: center;
    color: #555;
  }

</style>
